package smedi.ismedi.mobile.bff.controller.authortiy;

import com.smedi.ismedi.authority.starter.response.AuthorityAccessResponse;
import com.smedi.ismedi.authoritymanagement.api.dto.response.WebClientStructureResponse;
import com.smedi.ismedi.authoritymanagement.api.feign.RemoteAuthorityAccessFeignApi;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xulinjun
 * @Date: 2021-7-4 15:45
 */
@Slf4j
@RestController
@Api(tags = {"token身份验证接口"})
@RequestMapping("/mobilebff/v1/authorityAccess")
@AllArgsConstructor
public class AuthorityAccessController {
    private final RemoteAuthorityAccessFeignApi remoteAuthorityAccessFeignApi;

    /**
     * 校验令牌获取用户信息
     *
     * @param token
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "校验令牌获取用户信息")
    @GetMapping(value = "/validateTokenAndGetAuthorityAccessAndRefreshExpress")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "token", value = "令牌", dataType = "String"),
    })
    public ResponseData<AuthorityAccessResponse> getValidateTokenAndGetAuthorityAccessAndRefreshExpress(@RequestParam("token") String token) {
        return remoteAuthorityAccessFeignApi.getValidateTokenAndGetAuthorityAccessAndRefreshExpress(token);
    }

    /**
     * 根据用户获取有权限的菜单和路由
     *
     * @param rootCode
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "根据用户获取有权限的菜单和路由")
    @GetMapping(value = "/getMenuInfrastructure")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "rootCode", value = "根节点编码", dataType = "String", dataTypeClass = String.class)})
    public ResponseData<WebClientStructureResponse> getMenuInfrastructure(@RequestParam("rootCode") String rootCode) {
        return remoteAuthorityAccessFeignApi.getMenuInfrastructure(rootCode);
    }
}
